package leetcode.offer;

import org.junit.Test;

/**
 * @author LiDong
 * @version 1.0.0
 * @createTime 2021/11/22
 */
public class offer58I {


    /**
     * 输入一个英文句子，翻转句子中单词的顺序，但单词内字符的顺序不变。为简单起见，标点符号和普通字母一样处理。例如输入字符串"I am a student. "，则输出"student. a am I"。
     * <p>
     *  
     * <p>
     * 示例 1：
     * <p>
     * 输入: "the sky is blue"
     * 输出: "blue is sky the"
     *
     * @param s
     * @return
     */


    @Test
    public void test() {
        String str = " the sky is blue";
        System.out.println(reverseWords(str));
    }


    public String reverseWords(String s) {
        String[] s1 = s.trim().split(" ");
        StringBuilder str = new StringBuilder();
        for (int i = s1.length - 1; i >= 0; i--) {
            if (s1[i].equals("")) {
                continue;
            }
            str.append(s1[i] + " ");
        }
        return str.toString().trim();
    }

}
